package com.news.news.web;

import com.news.news.modle.Comment;
import com.news.news.modle.News;
import com.news.news.service.CommentService;
import com.news.news.service.UserNewsService;
import com.news.news.util.CommonResult;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/userApi/UserNewsController")
public class UserNewsController {

    @Resource
    UserNewsService userNewsService;

    /**
     * 获取用户新闻
     * @return
     */
    @RequestMapping("/mynewsList")
    public CommonResult mynewsList(@RequestHeader("userToken")String token){
        List<News> list = userNewsService.mynewsList(token);
        CommonResult commonResult = new CommonResult(200, list, "成功");
        return commonResult;
    }

    /**
     * 获取用户新闻
     * @return
     */
    @RequestMapping("/findUser")
    public CommonResult findUser(String password){
        Integer ret= userNewsService.findUser(password);

        CommonResult commonResult = new CommonResult(200, ret, "成功");
        return commonResult;
    }
    /**
     * 获取用户新闻
     * @return
     */
    @RequestMapping("/deleteNews")
    public CommonResult deleteNews(int id){
         userNewsService.deleteNews(id);

        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }



    /**
     * 获取用户新闻信息通过ID
     * @return
     */
    @RequestMapping("/findNewsById")
    public CommonResult findNewsById(int id){
        News news= userNewsService.findNewsById(id);


        CommonResult commonResult = new CommonResult(200, news, "修改状态成功");
        return commonResult;
    }
}
